package codegen.graphnetwork.model;

import codegen.groovy.graphnetwork.model.ValueChangeListener;
import java.util.ArrayList;

/**
 *
 * @author hungcuong
 */
public class Value {

    public String type;
    String name;
    public float value;
    //Value linkedValue;
    public Link link;
    public Node parent;
    public boolean linked;
    public boolean changable;
    public boolean isInput = true;
    public boolean defaultPin = false;
    ArrayList<ValueChangeListener> listeners = new ArrayList<ValueChangeListener>();
    public Status status;

    public enum Status {

        Init, Computing, Finished
    }

    public Value(String type, String name, float value) {
        this.type = type;
        this.name = name;
        this.value = value;
    }

    public void addChangeListener(ValueChangeListener listener) {
        listeners.add(listener);
    }

    public void onChange() {
        for (ValueChangeListener l : listeners) {
            l.onChange();
        }
    }

    public String getName() {
        return name;
    }

    public String getType() {
        return type;
    }

    public Status getStatus() {
        return status;
    }

    public Node getParent() {
        return parent;
    }

    public float getValue() {
        return this.value;
    }

    public void getLinkedValue() {
        this.value = this.link.input.value;
        this.status = Status.Finished;
    }

    public void setValue(float value) {
        this.value = value;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setLinked(boolean linked) {
        this.linked = linked;
    }

    public void setLink(Link link) {
        this.link = link;
    }

    public void setDefaultPin(boolean defaultPin) {
        this.defaultPin = defaultPin;
    }
}
